﻿
using System;
namespace FreeBroker
{
    public class InformerType
    {
        private InformerType(string category, string type)
        {
            // Hidden constructor, must instantiate with static method
            this.category = category;
            this.name = type;
        }

        public const string CAT_CALL = "Optionsschein";
        public const string CAT_CERTIFICATE = "Zertifikat";
        public const string CAT_FUND = "Fond";
        public const string CAT_BROKER = "Aktie";
        public const string CAT_INDEX = "Index";
        public const string CAT_BOND = "Anleihe";
        public const string CAT_CURRENCY = "Währung";

        private string category;
        /// <summary>
        ///     The main category for this type, use one of the constants.
        /// </summary>
        public string Category
        {
            get { return category; }
            set { category = value; }
        }

        private string name;
        /// <summary>
        ///     The type as read from web interface.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public static InformerType FromName(string type)
        {
            if (type != null)
            {
                string comp = type.ToLower();
                string category;
                if (comp.Contains("aktie"))
                {
                    category = CAT_BROKER;
                }
                else if (comp.Contains("index"))
                {
                    category = CAT_INDEX;
                }
                else if (comp.Contains("fonds"))
                {
                    category = CAT_FUND;
                }
                else if (comp.Contains("call") || comp.Contains("option"))
                {
                    category = CAT_CALL;
                }
                else if (comp.Contains("zertifikat"))
                {
                    category = CAT_CERTIFICATE;
                }
                else if (comp.Contains("anleihe"))
                {
                    category = CAT_BOND;
                }
                else if (comp.Contains("währung"))
                {
                    category = CAT_CURRENCY;
                }
                else
                {
                    Console.WriteLine("Unable to create informer type for given name: " + type);
                    return null;
                }
                return new InformerType(category, type);
            }
            return null;
        }
    }
}
